FILEFIND.GREP Function

Syntax

Line_List as C = FILEFIND.Grep(C file_pattern,C regular_expression[,N file_attribute[,C grep_format[,C regex_options]]])

Arguments

file_patternCharacter

A pattern to select file names using wildcard characters like '*' and '? '.

regular_expressionCharacter

A regular expression used to search the directory.

file_attributeNumeric

Default = 0 (normal files). The File_Attribute parameter is a numeric value specifying the type of file to find. You can find files that have one or more of the following attributes:

File Attribute
Description
FILE_FIND_NORMAL

Normal

FILE_FIND_READONLY

Read-only

FILE_FIND_HIDDEN

Hidden

FILE_FIND_SYSTEM

System

FILE_FIND_LABEL

Label

FILE_FIND_DIRECTORY

Directory

FILE_FIND_ARCHIVE

Archive

FILE_FIND_AND_FLAGS

Specifies that multiple flags should be ANDed together rather than ORed. By default flags are ORed.

FILE_FIND_NOT_READONLY

Files that are NOT readonly

FILE_FIND_NOT_DIRECTORY

Files that are NOT directory files

FILE_FIND_NOT_ARCHIVE

Files that do not have their archive bit turned on.

FILE_FIND_AND_NOT_FLAGS

Specifies that when multiple "NOT" flags are used that the flags should be ANDed together.

grep_formatCharacter

Character

\0

All text.

\N

Tagged text expression.

N

No copy of unmatched text.

F

Only process first match.

$(OFFSET)

Return the offset of the match.

$(LENGTH)

Return the length of the match.

$(END)

Return the ending offset of the match.

$(LINE)

Return the line the match started on.

$(ENDLINE)

Return the line the match ended on.

$(LINES)

Return the number of lines the match crosses.

$(LINETEXT)

Return the complete line(s) of text the match(es) occurred on.

$(LINEOFFSET)

Return the offset of the beggining of the match line.

$(ENDLINEOFFSET)

Return the offset of the end of the line the match ended on.

$(COUNT)

Return the number of matches encountered so far.

$(NEXTLINE)

Advance the search pointer to the next line.

$(FILENAME)

The name of file we are currently grepping

$(FULLFILENAME)

The fully qualified name of file we are currently grepping

$(RELATIVEFILENAME)

A partially qualified name of file we are currently grepping (only different than FILENAME if we using recursive function)

$(STOP)

Stops GREPing a file after one occurance is found. This lets you print a list of files that have a match instead of all the lines that in the file than matched.

regex_optionsCharacter

Default = "S". Specify which compatibility with a common implementation. ThE flags for Emacs, Awk, Grep, Egrep and Sed conventions allow the pattern to follow the conventions of those utilities (which have slightly different variants regarding what is escaped and what is not escaped).

Regex Option
Description
I

Ignore case

E

Follow Emacs conventions

A

Follow Awk conventions

G

Follow Grep conventions

EG

Follow Egrep conventions

S

Follow Sed conventions

X

Extended (similar to Awk but no need to escape '' inside of [])

Returns

Line_ListCharacter

A list containing of one line per file that contains text that matches the Regular_Expression. Each line contains the filename, line number, and the line containing the matching text.

Description

Returns a string containing all the files - you can specify what greps listed.

Discussion

The FILEFIND.GREP() method executes a regular expression against the contents of the files in the current directory that match a specified file pattern and returns a list of filenames and text.

Example

file.dir_put("c:\\")
? FILEFIND.grep("*.txt", "(W|w)indows")
= osver.txt 2:Microsoft Windows 2000 Version 5.00.2195
vpn setup.txt 1:Windows 2000/ME

See Also